import { ILoadMapTypeAll } from '@/common';
import { ManageCommonAPI } from '@/pages/type';
import { getSelectDataMapList, getTenantID } from '@/utils';
import { useEffect, useState } from 'react';
import { getStorageTreeService } from '../../Assetmanagement/AssetAllot/services';

/** 材料列表搜索 */
const getAssetSearchList = (loadObj: Record<string, any>): any => {
  /**资产分类数据字典*/
  // const materialTypeMapList = loadObj?.loadMapInfo?.[`${getTenantID()}${ILoadMapTypeAll.MATERIAL_TYPE}`];
  const materialTypeMapList = getSelectDataMapList(loadObj?.loadMapInfo?.[`${getTenantID()}${ILoadMapTypeAll.MATERIAL_TYPE}`], 'name', 'id', true);

  /** 仓库树数据 */
  const [storageList, setStorageList] = useState<any>([]);

  /** 获取仓库树回调 */
  const updataGetStorage = (res: any) => {
    if (res && res?.msgFlag) {
      setStorageList(res?.obj);
    }
  };

  /** 获取仓库树 */
  const { getStorageLoading, getStorageRun } = getStorageTreeService(updataGetStorage);

  useEffect(() => {
    getStorageRun();
  }, []);

  const searchColumns: ManageCommonAPI.ISearchList = [
    {
      name: 'assetName',
      placeholder: '资产名称',
      label: '资产名称',
      componentType: 'Input',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
    },
    {
      name: 'assetCode',
      placeholder: '资产编号',
      label: '资产编号',
      componentType: 'Input',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
    },
    {
      name: 'assetClass',
      placeholder: '资产分类',
      label: '资产分类',
      componentType: 'TreeSelect',
      dataSource: materialTypeMapList,
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
      fieldNames: {
        label: 'name',
        value: 'id',
        children: 'children',
      },
    },
    {
      name: 'brandType',
      placeholder: '品牌',
      label: '品牌',
      componentType: 'Input',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
    },
    {
      name: 'paramsInfo',
      placeholder: '规格型号',
      label: '规格型号',
      componentType: 'Input',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
    },
    {
      name: 'assetStoreId',
      placeholder: '所属仓库',
      label: '所属仓库',
      componentType: 'TreeSelect',
      dataSource: storageList,
      allowClear: true,
      md: 4,
      sm: 36,
      whetherSenior: false,
      fieldNames: {
        label: 'storeName',
        value: 'id',
        children: 'children',
      },
    },
  ];

  return searchColumns;
};

export { getAssetSearchList };
